home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 2002 November / SGI Freeware 2002 November - Disc 1.iso / dist / fw_exmh.idb / usr / freeware / lib / exmh-2.5 / html_hr.tcl.z / html_hr.tcl
Text File  |  2002-07-08  |  3KB  |  99 lines

  1. proc Hr_Init {win} {
  2.     upvar #0 HM$win var
  3.     $win tag configure hrShade -relief sunken -borderwidth 2
  4.     $win tag configure hrNoShade -relief flat -borderwidth 2 \
  5.         -background black -foreground white
  6.     $win tag bind hrShade <ButtonRelease-1> {Hr_Edit %W %x %y}
  7.     $win tag bind hrNoShade <ButtonRelease-1> {Hr_Edit %W %x %y}
  8.     set var(S_hrWidth) {}
  9.     set var(S_hrSize) {}
  10.     bind $win <Configure> {
  11.         HrConfig %W
  12.     }
  13. }
  14. proc HMtag_hr {win param text} {
  15.     upvar #0 HM$win var
  16.     set size 2
  17.     HMextract_param $param size
  18.     if {[lsearch $var(S_hrSize) hrSize$size] < 0} {
  19.         foreach font [list [HMx_font times $size * *] \
  20.                 [HMx_font courier $size * *] \
  21.                 fixed] {
  22.         if ![catch {$win tag configure hrSize$size -font $font}] {
  23.             lappend var(S_hrSize) hrSize$size
  24.             break
  25.         }
  26.         }
  27.     }
  28.     set align center
  29.     HMextract_param $param align
  30.     set align [string toupper $align]
  31.     set width 100%
  32.     HMextract_param $param width
  33.     if {[lsearch $var(S_hrWidth) hr$align$width] < 0} {
  34.         lappend var(S_hrWidth) hr$align$width
  35.         HrConfig $win    ;# Config tag for width/alignment combination
  36.     }
  37.     if [HMextract_param $param noshade] {
  38.         set shade hrNoShade
  39.     } else {
  40.         set shade hrShade
  41.     }
  42.     set tags "hrSize$size space"
  43.  
  44.     Text_Insert $win  $var(S_insert) "\n" "$tags $var(listtags)"
  45.     Text_Insert $win  $var(S_insert) "\t" "$tags $shade hr$align$width $var(listtags)"
  46.     Text_Insert $win  $var(S_insert) "\n" "$tags $var(listtags)"
  47. }
  48. # Called in response to configure events to adjust the size of hr rules.
  49. proc HrConfig {win} {
  50.     upvar #0 HM$win var
  51.     foreach name $var(S_hrWidth) {
  52.         set width 100%
  53.         set align CENTER
  54.         regexp hr(LEFT|RIGHT|CENTER)(.+) $name x align width
  55.         set W [winfo width $win]
  56.         if [regexp (.+)% $width x relw] {
  57.         set width [expr $W*$relw/100]
  58.         }
  59.         switch $align {
  60.         LEFT    {$win tag configure $name -tabs $width}
  61.         RIGHT    {
  62.             $win tag configure $name -lmargin1 [expr $W-$width]
  63.             $win tag configure $name -tabs $width
  64.         }
  65.         CENTER -
  66.         default    {
  67.             set offset [expr ($W-$width)/2]
  68.             $win tag configure $name -lmargin1 $offset
  69.             $win tag configure $name -tabs [expr $width+$offset]
  70.         }
  71.         }
  72.     }
  73. }
  74.  
  75. proc Hr_Edit {win x y} {
  76.     upvar HM$win var
  77.  
  78.     set mark [$win mark prev @$x,$y]
  79.     while {[string length $mark]} {
  80.     set htag [Mark_Htag $win $mark]
  81.     if {[string length $htag]} {
  82.         return [HrEdit $win $mark $htag]
  83.     }
  84.     set mark [$win mark prev $mark]
  85.     }
  86. }
  87. proc HrEdit {win mark htag} {
  88.     Mark_SplitTag $htag tag param
  89.     set info [Dialog_Htag $win {hr width= align= shade=} $param "Horizontal Rule"]
  90.     if {[llength $info] > 0} {
  91.     set param [lindex $info 1]
  92.     Text_MarkSet $win insert $mark
  93.     Mark_ReadTags $win insert force
  94.     Text_Delete $win insert "insert +2lines"
  95.     Mark_Remove $win $mark
  96.     Input_Html $win <[string trim "hr $param"]>
  97.     }
  98. }
  99.